package com.ruoyi.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AhhcPatients;
import com.ruoyi.system.service.IAhhcPatientsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 注册时自行填写，手机号码和注册时间不能变更，其余可修改Controller
 *
 * @author ruoyi
 * @date 2025-03-14
 */
@RestController
@RequestMapping("/system/patients")
public class AhhcPatientsController extends BaseController
{
    @Autowired
    private IAhhcPatientsService ahhcPatientsService;

    /**
     * 查询注册时自行填写，手机号码和注册时间不能变更，其余可修改列表
     */
    @PreAuthorize("@ss.hasPermi('system:patients:list')")
    @GetMapping("/list")
    public TableDataInfo list(AhhcPatients ahhcPatients)
    {
        startPage();
        List<AhhcPatients> list = ahhcPatientsService.selectAhhcPatientsList(ahhcPatients);
        return getDataTable(list);
    }

    /**
     * 导出注册时自行填写，手机号码和注册时间不能变更，其余可修改列表
     */
    @PreAuthorize("@ss.hasPermi('system:patients:export')")
    @Log(title = "注册时自行填写，手机号码和注册时间不能变更，其余可修改", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AhhcPatients ahhcPatients)
    {
        List<AhhcPatients> list = ahhcPatientsService.selectAhhcPatientsList(ahhcPatients);
        ExcelUtil<AhhcPatients> util = new ExcelUtil<AhhcPatients>(AhhcPatients.class);
        util.exportExcel(response, list, "注册时自行填写，手机号码和注册时间不能变更，其余可修改数据");
    }

    /**
     * 获取注册时自行填写，手机号码和注册时间不能变更，其余可修改详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:patients:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ahhcPatientsService.selectAhhcPatientsById(id));
    }

    /**
     * 新增注册时自行填写，手机号码和注册时间不能变更，其余可修改
     */
    @PreAuthorize("@ss.hasPermi('system:patients:add')")
    @Log(title = "注册时自行填写，手机号码和注册时间不能变更，其余可修改", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AhhcPatients ahhcPatients)
    {
      String id = "HZ"+ahhcPatients.getPhoneNumber();
      ahhcPatients.setId(id);
        return toAjax(ahhcPatientsService.insertAhhcPatients(ahhcPatients));
    }
    /**
     * 获取患者列表
     */
    @GetMapping("/getshow")
    public AjaxResult getPatients()
    {
        List<AhhcPatients> list = ahhcPatientsService.selectshow();
        return success(list);
    }

    /**
     * 修改注册时自行填写，手机号码和注册时间不能变更，其余可修改
     */
    @PreAuthorize("@ss.hasPermi('system:patients:edit')")
    @Log(title = "注册时自行填写，手机号码和注册时间不能变更，其余可修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AhhcPatients ahhcPatients)
    {
        return toAjax(ahhcPatientsService.updateAhhcPatients(ahhcPatients));
    }

    /**
     * 删除注册时自行填写，手机号码和注册时间不能变更，其余可修改
     */
    @PreAuthorize("@ss.hasPermi('system:patients:remove')")
    @Log(title = "注册时自行填写，手机号码和注册时间不能变更，其余可修改", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ahhcPatientsService.deleteAhhcPatientsByIds(ids));
    }
}
